<?php
/**
 * Created by PhpStorm.
 * User: function
 * Date: 2018-04-16
 * Time: 9:14
 */

namespace app\seller\controller;
use app\common\controller\Seller;
use app\common\logic\OrderLogic;
use think\Request;
use app\common\model\Express;
use app\common\model\Pay;
use app\common\model\UnifiedOrder;
class Order extends Seller
{
    protected $authenticate=null;
    
    public function index()
    {
        $params = paramForm();
//        if(!isset($params['mid']))error('moduleid参数必填');
        $logic = new OrderLogic();
        
        if(Request::instance()->isAjax()){
            $logic->setSql($params);
 
            $logic->setValue('size',20);
            $logic->setValue('paginate',1);
            $logic->setValue('order','create_time desc');
            $logic->setValue('with','purchaser');//关联购买表啊
            $logic->setValue('condition',['seller'=>$this->getSellerId()]);
           
            //$logic->setValue('with','purchaser,member');//关联购买表啊
            $list = $logic->prepareDataProvider();
            success($list);
        }else{
//            $this->assign('mid',$params['mid']);
            return $this->fetch();
        }
        
    }
    
    public function edit($id){
        $logic = new OrderLogic();
        $logic->setValue('with','module,member');
        $model = $logic->findModel($id);
        
        if($model->seller!=$this->getSellerId()){
            $this->error('只能操作自己的订单');
        }
        
        $model->unifiedOrder = $logic->getUnifiedOrder($id);
        $model->purchaser = $logic->getPurchaser($id);
        $pay = Pay::get(['out_trade_no'=>$model->unifiedOrder->out_trade_no]);

        $this->assign('pay',$pay);
        $this->assign('express',Express::all());
        $this->assign('model', $model);
        return $this->fetch();
    }
    
    public function send(){
        $rule = [
            'send_no|订单号'=>'require',
            'send_type|物流'=>'require',
            'send_type_id|物流序号'=>'require',
        ];
        $params = paramForm();
        $this->validate($params,$rule);
        
        
    }
    
    
    
    
}